<!--
 * @Descripttion: 说明
 * @version: V1.0
 * @Author: fgz
 * @Date: 2021-10-25 11:53:28
 * @LastEditors: fgz
 * @LastEditTime: 2021-10-25 17:20:52
-->
<template>
  <div class="goods-container">
    <!-- 左侧图片 -->
    <div class="thumb">
      <div class="custom-control custom-checkbox">
        <!-- 复选框 -->
        <input type="checkbox" class="custom-control-input" :id="'cb'+id" :checked="state" @change="stateChange"/>
        <label :for="'cb'+id" class="custom-control-label">
          <!-- 商品的缩略图 -->
          <img :src="pic" alt="" />
        </label>
      </div>
    </div>
    <!-- 右侧信息区域 -->
    <div class="goods-info">
      <!-- 商品标题 -->
      <h6 class="goods-title">{{title}}</h6>
      <div class="goods-info-bottom">
        <!-- 商品价格 -->
        <span class="goods-price">￥{{price}}</span>
        <!-- 商品数量 -->
        <Counter :num="count" :id="id"></Counter>
      </div>
    </div>
  </div>
</template>

<script>
import Counter from '@/components/Counter/Counter.vue'
export default {
  name: '',
  components: {Counter},
  props: {
    // 商品id
    id:{
      require:true,
      type: Number
    },
    title:{
      type:String,
      default: '',
    },
    pic: {
      default: '',
      type: String
    },
    price: {
      default: 0,
      type: Number
    },
    state: {
      default: true,
      type: Boolean
    },
    count: {
      type: Number,
      default: 1
    }
  },
  data () {
    return {
      
    }
  },
  methods: {
    stateChange(e){
      const newState = e.target.checked;
      this.$emit('state-change',{id:this.id,value: newState});
    }
  },
  mounted(){},
}
</script>

<style lang='less' scoped>
.goods-container {
  + .goods-container{
    border-top: 1px solid #efefef;
  }
  padding: 10px;
  display: flex;
  .thumb{
    display: flex;
    align-items: center;
    img{
      width: 100px;
      height: 100px;
      margin:0 10px;
    }
    .custom-checkbox{
      display: flex;
      align-items: center;
      justify-content: space-between;
      .custom-control-input,.custom-control-label{
        margin: 5px;
      }
    }
  }
  .goods-info{
    display: flex;
    flex-direction: column;
    margin: 5px;
    .goods-title{
      flex-grow: 1;
    }
    .goods-price{
      color:red;
    }
    .goods-info-bottom{
      display: flex;
      align-items: center;
      justify-content: space-between;
    }
  }
}
</style>
